<template>
  <div class="header">
    <!-- 展开 -->
    <div v-if="!collapse" class="collapse-login">
      <div class="login">
        <img src="./../../assets/img/logon.png" alt="">
        <div class="sidebar-title">
          <h1>华普能源管理平台</h1>
          <h6>Huapu energy management platform</h6>
        </div>
      </div>
    </div>
    <!-- 折叠 -->
    <div v-if="collapse" class="m-collapse-login">
      <div class="login">
        <img src="./../../assets/img/logon.png" alt="">
        <div class="sidebar-title">
          <h1>华普</h1>
          <h6>Huapu</h6>
        </div>
      </div>
    </div>
    <!-- 折叠按钮 -->
    <div class="box-right">
      <div class="box-top">
        <div class="collapse-btn" @click="collapseChage">
          <i v-if="!collapse" class="el-icon-s-fold" />
          <i v-else class="el-icon-s-unfold" />
        </div>
        <div class="header-right">
          <div class="header-user-con">
            <!-- 时间 -->
            <div>
              <TimeViews />
            </div>
            <el-select v-model="value" class="clientdata" placeholder="请选择" @change="changeSubjectType">
              <el-option
                v-for="item in clientdata"
                :key="item.pkid"
                :label="item.name"
                :value="item.pkid"
              />
            </el-select>
            <!-- 全屏显示 -->
            <div class="btn-fullscreen" @click="handleFullScreen">
              <el-tooltip effect="dark" :content="fullscreen?`取消全屏`:`全屏`" placement="bottom">
                <i class="el-icon-rank" />
              </el-tooltip>
            </div>
            <div class="btn-out" @click="loginOut">
              <i class="icon iconfont icon-exit" />
            </div>
          </div>
        </div>
      </div>
      <div class="box-bottom">
        <v-tags />
      </div>
    </div>

  </div>
</template>
<script>
import bus from '../common/bus'
import vTags from './Tags.vue'
import TimeViews from '../common/components/time'
export default {
  components: {
    vTags,
    TimeViews
  },
  props: {
    clientdata: {
      type: Array,
      default: null
    }
  },
  data() {
    return {
      collapse: false,
      fullscreen: false,
      name: 'linxin',
      message: 2,
      value: ''
    }
  },
  computed: {
    username() {
      const username = localStorage.getItem('ms_username')
      return username || this.name
    }
  },
  watch: {
    clientdata(val) {
      this.value = val[0].name
    }
  },
  mounted() {
    if (document.body.clientWidth < 1500) {
      this.collapseChage()
    }
  },
  methods: {
    // 侧边栏折叠
    collapseChage() {
      this.collapse = !this.collapse
      bus.$emit('collapse', this.collapse)
    },
    // 退出登录
    loginOut() {
      this.$confirm('此操作将退出登录状态, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // localStorage.removeItem('ms_username')
        localStorage.clear()
        this.$message({
          type: 'success',
          message: '退出成功!'
        })
        this.$router.push('/login')
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    },
    // 获取更改后的Id
    changeSubjectType(vId) {
      console.log(vId)
    },
    // 全屏事件
    handleFullScreen() {
      const element = document.documentElement
      if (this.fullscreen) {
        if (document.exitFullscreen) {
          document.exitFullscreen()
        } else if (document.webkitCancelFullScreen) {
          document.webkitCancelFullScreen()
        } else if (document.mozCancelFullScreen) {
          document.mozCancelFullScreen()
        } else if (document.msExitFullscreen) {
          document.msExitFullscreen()
        }
      } else {
        if (element.requestFullscreen) {
          element.requestFullscreen()
        } else if (element.webkitRequestFullScreen) {
          element.webkitRequestFullScreen()
        } else if (element.mozRequestFullScreen) {
          element.mozRequestFullScreen()
        } else if (element.msRequestFullscreen) {
          // IE11
          element.msRequestFullscreen()
        }
      }
      this.fullscreen = !this.fullscreen
    }
  }
}
</script>
<style scoped lang="scss">
.header {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  height: 55px;
  font-size: 22px;
  color: #fff;
  .collapse-btn {
    float: left;
    padding: 0 21px;
    cursor: pointer;
    line-height: 55px;
  }
  .collapse-login{
    float: left;
    padding: 0;
    cursor: pointer;
    height: 55px;
    width: 210px;
    background: #009B79;
    display: flex;
    align-items: center;
    justify-content: center;
    .login img{
      float:left;
      width: 32px;
      height: 32px;
      margin-right: 0px;
    }
    .login h1{
      float: left;
      font-size: 20px;
      padding-left: 5px;
      font-family: MF YanSong Noncommercial;
      font-weight: 900;
      margin: 0;
    }
    .login h6{
      float: left;
      font-size: xx-small;
      padding-left: 5px;
      font-family: Arial;
      font-weight: 400;
      margin: 0;
    }
  }
  .m-collapse-login{
    float: left;
    padding: 0;
    cursor: pointer;
    height:55px;
    width: 64px;
    background: #009b79;
    display: flex;
    align-items: center;
    justify-content: center;
    .login{
      text-align: center;
    }
    .login img{
      width: 32px;
      height: 32px;
      vertical-align: middle;
    }
    .login h1{
      font-size: 16px;
      font-family: MF YanSong Noncommercial;
      font-weight: 900;
      margin: 0;
    }
    .login h6{
      font-size: 8px;
      font-family: Arial;
      font-weight: 400;
      margin: 0;
    }
  }
  .box-right{
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .box-bottom{
      background: #273142;
    }
    background: #009B79;
  }
}

.header-right {
    float: right;
    padding-right: 5px;
    .header-user-con {
      display: flex;
      height:55px;
      align-items: center;
    }
    .btn-fullscreen {
      transform: rotate(45deg);
      margin-right: 5px;
      font-size: 24px;
    }
    .btn-bell,
    .btn-fullscreen {
      margin: 0 10px;
      position: relative;
      width: 30px;
      height: 30px;
      text-align: center;
      border-radius: 15px;
      cursor: pointer;
    }
    .btn-bell-badge {
      position: absolute;
      right: 0;
      top: -2px;
      width: 8px;
      height: 8px;
      border-radius: 4px;
      background: #f56c6c;
      color: #fff;
    }
    .btn-bell .el-icon-bell {
      color: #fff;
    }
    .user-name {
      margin-left: 10px;
      margin-right: 15px;
    }
    .user-avator {
      margin-left: 10px;
    }
    .user-avator img {
      display: block;
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
    .el-dropdown-link {
      color: #fff;
      cursor: pointer;
    }
    .el-dropdown-menu__item {
      text-align: center;
    }
    .btn-out{
      margin: 0 10px;
      .icon{
        font-size: 30px;
      }
    }
    .clientdata{
      margin: 0 10px;
    }
}
</style>
<style>
.clientdata .el-input__inner{
  background-color: #009B79;
  border:1px solid #009B79;
  color: #f5f7fa;
}
.el-select .el-input.is-focus .el-input__inner,.el-select .el-input__inner:focus{
  border-color: #009B79;
}
</style>
